package gui;

import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import logic.InformationsExtractor;
import utils.Constants;
import utils.Graphic;

public class GUIManager {

	private Graphic graphic;

	public void gerenarateGraphic(String path) {
		this.graphic = new Graphic();
		InformationsExtractor informations = new InformationsExtractor();
		List<List<String>> transformations = informations
				.getTransformationsList(path);
		TreeMap<String, TreeMap<String, Integer>> ciclomaticComplexityInfo = informations
				.getMetricCost(transformations,
						Constants.CICLOMATIC_COMPLEXITY_TYPE);
		TreeMap<String, TreeMap<String, Integer>> printStatementInfo = informations
				.getMetricCost(transformations, Constants.PRINT_STATEMENT_TYPE);
		TreeMap<String, TreeMap<String, Integer>> NMTRInfo = informations
				.getMetricCost(transformations, Constants.NMTR_TYPE);
		TreeMap<String, Integer> CCGraphicDatas = informations
				.sumTransformationCost(ciclomaticComplexityInfo);
		TreeMap<String, Integer> PSGraphicDatas = informations
				.sumTransformationCost(printStatementInfo);
		TreeMap<String, Integer> NMTRGraphicDatas = informations
				.sumTransformationCost(NMTRInfo);

		Set<String> CCKeys = CCGraphicDatas.keySet();
		Set<String> PSKeys = PSGraphicDatas.keySet();
		Set<String> NMTRKeys = NMTRGraphicDatas.keySet();
		for (String tt : CCKeys) {
			graphic.setValues(CCGraphicDatas.get(tt), tt, Constants.CC_METRIC);
		}
		for (String tt : PSKeys) {
			graphic.setValues(PSGraphicDatas.get(tt), tt, Constants.PS_METRIC);
		}
		for (String tt : NMTRKeys) {
			graphic.setValues(NMTRGraphicDatas.get(tt), tt,
					Constants.NMTR_METRIC);
		}
		graphic.displayGraphic(Constants.GRAPHIC_TITLE,
				Constants.TEXT_TRANSFORMATION_NAME, Constants.VERTICAL_COST);
		informations.printCompareMetric(NMTRInfo);
		//informations.printMetricCost(NMTRInfo);
	}
}
